import request from "@/plugins/axios"
import type { AxiosRequestConfig } from "axios"

function useRequest(prefix: string = '') {
    const requestProxy = {
        get: <T = any> (url: string, data?: any, options?: AxiosRequestConfig) => {
            return request.get<T>(`${prefix}${url}`, data, options);
        },
        post: <T = any> (url: string, data?: any, options?: AxiosRequestConfig) => {
            return request.post<T>(`${prefix}${url}`, data, options);
        },
        delete: <T = any> (url: string, data?: any, options?: AxiosRequestConfig) => {
            return request.delete<T>(`${prefix}${url}`, data, options);
        },
        put: <T = any> (url: string, data?: any, options?: AxiosRequestConfig) => {
            return request.put<T>(`${prefix}${url}`, data, options);
        },
        getUrl: (url: string = '') => {
            return `${prefix}${url}`;
        }
    } as const;

    return requestProxy;
}

export default useRequest;